<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    {{--<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />--}}
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="{{asset('xAdmin/css/font.css')}}">
    <link rel="stylesheet" href="{{asset('xAdmin/css/xadmin.css')}}">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="{{asset('xAdmin/lib/layui/layui.js')}}" charset="utf-8"></script>
    <script type="text/javascript" src="{{asset('xAdmin/js/xadmin.js')}}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
        .width-400 {
            width: 400px;
        }
    </style>
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="store-auth">
        {{csrf_field()}}
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>权限名称
            </label>
            <div class="layui-input-block width-400">
                <input type="text" id="name" name="name" lay-verify="required"
                       autocomplete="off" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="server" class="layui-form-label">
                <span class="x-red">*</span>微服务的名
            </label>
            <div class="layui-input-block width-400">
                <input type="text" id="server" name="server" lay-verify="required|name"
                       autocomplete="off" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="module" class="layui-form-label">
                <span class="x-red">*</span>模块的名
            </label>
            <div class="layui-input-block width-400">
                <input type="text" id="module" name="module" lay-verify="required|name"
                       autocomplete="off" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="controller" class="layui-form-label">
                <span class="x-red">*</span>控制器的名
            </label>
            <div class="layui-input-block width-400">
                <input type="text" id="controller" name="controller" lay-verify="required|name"
                       autocomplete="off" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="action" class="layui-form-label">
                <span class="x-red">*</span>方法的名
            </label>
            <div class="layui-input-block width-400">
                <input type="text" id="action" name="action" lay-verify="required|name"
                       autocomplete="off" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="store" lay-submit="">保存</button>
        </div>
    </form>
</div>
<script>
    // 信息保存
    layui.use(['form','layer'], function(){
        let $ = layui.jquery;
        let form = layui.form, layer = layui.layer;
        //自定义验证规则
        form.verify({
            name: function(value){
                let reg = /^[a-zA-Z]+$/;
                if(!reg.test(value)){
                    return '该字段必须是英文';
                }
            },
        });
        //监听提交
        form.on('submit(store)', function(){
            $.ajax({
                url: '{{url("backstage/user/auth/store")}}',
                type: 'POST',
                dataType: 'json',
                data: $('#store-auth').serialize(),
                success: function (result) {
                    if (result.status === 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 2000
                        }, function () {
                            // 获得frame索引
                            let index = parent.layer.getFrameIndex(window.name);
                            // 关闭当前frame
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 2000
                        }, function () {
                            // 获得frame索引
                            let index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                },
                error: function () {
                    layer.msg('保存异常，请重试！');
                    return false;
                }
            });
            return false;
        });
    });
</script>
</body>

</html>
